/** 
  总评成绩表（分项）
*/
<template>
  <div class="subItem-overall-score-container">
    <div style="height: 40px;">
      <el-breadcrumb separator="/" class="float-left" style="padding-top: 8px;">
        <el-breadcrumb-item :to="{ path: '/courseScoreMana' }">
          <span @click="backToMain()">{{ $t('courseScoreMana.courseScoreMana') }}</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t('courseScoreMana.subItemOverallAssessScore') }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="float-right">
        <el-button type="text" @click="backToMain()">{{ $t('common.btn.back') }}</el-button>
      </div>
    </div>
    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
      <div class="title">
        <div class="float-left">
          {{ $t('courseScoreMana.subItemOverallAssessScore') }}
        </div>
        <div class="float-right">
          <!-- 打印 -->
          <el-button @click="printScoreTable()">{{ $t('scoreMangementBase.printing') }}</el-button>
          <!-- 导出 -->
          <el-button @click="exportScoreTable()">{{ $t('scoreMangementBase.export') }}</el-button>
        </div>
      </div>
      <div class="blank-score-sheet">
        <div class="blank-title">{{ $t('scoreEntryMana.tjCollege') }}{{ basicInfo.calendarYearTermCn }}{{ $t('courseScoreMana.subItemEvalScoreSheet') }}</div>
        <el-row class="blank-sub-title">
          <!-- 课程名称 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.courseName') }}：{{ basicInfo.courseName }}
          </el-col>
          <!-- 课程代码 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.courseCode') }}：{{ basicInfo.courseCode }}
          </el-col>
          <!-- 课程序号 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.courseNum') }}：{{ basicInfo.courseNo }}
          </el-col>
        </el-row>
        <el-row class="blank-sub-title">
          <!-- 开课学院 -->
          <el-col :span="8">
            {{ $t('scoreEntrySwitch.startCollege') }}：{{ basicInfo.facultyI18n }}
          </el-col>
          <!-- 教师 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.tearcher') }}：{{ basicInfo.teacherCode }}{{ basicInfo.teacherName }}
          </el-col>
          <!-- 班级人数 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.classSize') }}：{{ basicInfo.selectNum }}
          </el-col>
        </el-row>
        <el-row class="blank-sub-title">
          <!-- 成绩类型 -->
          <el-col :span="24">
            {{ $t('scoreEntryMana.gradeType') }}：{{ basicInfo.scoreStructure }}
          </el-col>
        </el-row>
        <el-row style="margin: 15px 0;">
          <el-col :span="24">
            <el-table border :data="dataList" size="mini">
              <!-- 序号 -->
              <el-table-column :label="$t('scoreEntryMana.serialNumber')" type="index" align="center" width="80"></el-table-column>
              <!-- 学号 -->
              <edu-table-column :label="$t('scoreMangementBase.studentId')" prop="studentId" align="center"></edu-table-column>
              <!-- 姓名 -->
              <edu-table-column :label="$t('scoreMangementBase.studentName')" prop="studentName" align="center"></edu-table-column>
              <!-- 平时1成绩 -->
              <edu-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containDailyScore1" :label="$t('scoreEntryMana.usuallyOneScore')" prop="exam1" align="center">
                <template slot-scope="scope">
                  <span :style="scope.row.exam1Flag === 'Y' ? 'color: red;' : ''">{{ scope.row.exam1 }}</span>
                </template>
              </edu-table-column>
              <!-- 平时2成绩 -->
              <edu-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containDailyScore2" :label="$t('scoreEntryMana.usuallyTwoScore')" prop="exam2" align="center">
                <template slot-scope="scope">
                  <span :style="scope.row.exam2Flag === 'Y' ? 'color: red;' : ''">{{ scope.row.exam2 }}</span>
                </template>
              </edu-table-column>
              <!-- 期中成绩 -->
              <edu-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containMidtermScore" :label="$t('scoreEntryMana.midTermGrades')" prop="middleScore" align="center">
                <template slot-scope="scope">
                  <span :style="scope.row.middleScoreFlag === 'Y' ? 'color: red;' : ''">{{ scope.row.middleScore }}</span>
                </template>
              </edu-table-column>
              <!-- 期末成绩 -->
              <edu-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containFinalScore" :label="$t('scoreEntryMana.finalGrade')" prop="finalScore" align="center">
                <template slot-scope="scope">
                  <span :style="scope.row.finalScoreFlag === 'Y' ? 'color: red;' : ''">{{ scope.row.finalScore }}</span>
                </template>
              </edu-table-column>
              <!-- 总评成绩 -->
              <edu-table-column :label="$t('scoreEntryMana.overallRating')" prop="totalScore" align="center">
                <template slot-scope="scope">
                  <span :style="scope.row.isPass === '0' ? 'color: red;' : ''">{{ scope.row.totalScore }}</span>
                </template>
              </edu-table-column>
            </el-table>
          </el-col>
        </el-row>
      </div>
    </el-card>
    <edu-export-dialog
      :disabled="exportButton"
      :title="$t('message.prompt')"
      ref="downloadRef"
      :data="exportResult">
    </edu-export-dialog>
  </div>
</template>
<script>
import baseUrl from 'common/src/api/scoreManagement/env';
import scoreManagementApi from 'common/src/api/scoreManagement/scoreManagement';
export default {
  components: {
  },
  data () {
    return {
      basicInfo: {},
      dataList: [],
      exportButton: false,
      exportResult: null
    }
  },
  props: {
    detailInfo: {
      type: Object,
      default: () => {}
    }
  },
  created() {

  },
  mounted() {
    scoreManagementApi.getMinorGradeInfos(this.detailInfo).then(res => {
      if (res.code === 200) {
        this.basicInfo = res.data
        this.dataList = this.basicInfo.studentList
      }
    })
  },
  methods: {
    // 校验特殊字符$
    checkSpecial(rule, value, callback) {
      let regEn = /[`$]/im
      if (regEn.test(value)) {
        callback(new Error(this.$t('graduateBase.specialText')))
      } else {
        callback()
      }
    },
    // 返回主页
    backToMain() {
      this.$emit('refresh-main-page')
    },
    // 导出
    exportScoreTable() {
      this.exportResult = null
      this.$refs.downloadRef.open()
      this.exportButton = true
      window.location.href = `${baseUrl}/minorCourseGradeManageController/exportMinorGradeTotalTable?calendarId=` + this.basicInfo.calendarId + '&teachingClassId=' + this.basicInfo.teachingClassId + '&campus=' + this.basicInfo.campus + '&examType=' + this.detailInfo.examType + '&language=' + this.$store.getters.language + '&sourceType=1'
      setTimeout(() => {
        this.$refs.downloadRef.close()
        this.exportButton = false
      }, 3000)  
    },
    // 打印
    printScoreTable() {
      let params = `${baseUrl}/minorCourseGradeManageController/exportMinorGradeTotalTable?calendarId=` + this.basicInfo.calendarId + '&teachingClassId=' + this.basicInfo.teachingClassId + '&campus=' + this.basicInfo.campus + '&examType=' + this.detailInfo.examType + '&language=' + this.$store.getters.language + '&sourceType=1'
      window.open(params)
    }
  }
}
</script>

<style lang="scss" scoped>
  .subItem-overall-score-container ::v-deep {
    .title {
      margin-bottom: 40px;
      font-size: 18px;
    }
    .blank-title {
      margin-bottom: 40px;
      text-align: center;
      font-size: 18px;
    }
    .blank-sub-title {
      padding: 8px 0;
      font-size: 12px;
    }
  }
</style>